// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import Vant from 'vant';
import 'vant/lib/index.css';
import "./assets/reset.css"
import "./assets/rem.js"
import axios from "axios"
import store from "./store/index"

Vue.filter('capitalize', function (value,a1) {
   // alert(a1)
        console.log(a1)
        if(a1){
            return value.toFixed(a1)
        }else{

            return  value.toFixed(2)

        }
      

  })

// axios 的默认全局配置
axios.defaults.baseURL = 'https://api.it120.cc/small4';

Vue.prototype.http = axios
Vue.use(Vant);
Vue.config.productionTip = false

router.beforeEach((to, from, next) => {
    // /a?id=1 /a?id=3
    if (to.matched.some(record => record.meta.requiresAuth)) {
      // this route requires auth, check if logged in
      // if not, redirect to login page.

      var token = localStorage.getItem("token");
      if(token){
            next()
      }else{
        next({
            path: '/login',
            query: { redirect: to.fullPath }
          })
      }
    }else {

        next() // 确保一定要调用 next()

    }
  })




new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
